package Market;

import java.io.Serializable;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Ratuil
 * Date: 07.03.13
 * Time: 14:31
 * To change this template use File | Settings | File Templates.
 */
public class MarketStore implements Serializable {
    private Collection<Object> store;
    private Collection<Employee>employees;
    private HashMap<String,LinkedList<Product>> categories;
    private List<Product> products;
    private List<Sale>sales;

    public MarketStore(){
        store=new ArrayList<Object>(3);

        employees = new ArrayList<Employee>();
        categories = new HashMap<String, LinkedList<Product>>();
        sales=new ArrayList<Sale>();

        store.add(employees);
        store.add(categories);
        store.add(sales);

        products = new LinkedList<Product>();
    }

    protected Collection<Object>getStore(){return store;}
    protected void setStore(Collection<Object>s){store=s;}

    protected static class Employee implements Serializable{
        //private static int id=1;
        String name;
        double salary;
        Date hireDay;
        double sellCount;
        Employee(String name,double salary,int year,int month,int day){
            this.name = name;
            this.salary = salary;
            GregorianCalendar calendar=new GregorianCalendar(year, month-1, day);
            hireDay = calendar.getTime();
        }
        @Override
        public boolean equals(Object otherObj){
            if(this==otherObj)return true;
            if(otherObj==null)return false;
            if(getClass()!=otherObj.getClass())return false;
            Employee other=(Employee)otherObj;
            return name.equals(other.getName())
                    && salary==other.salary
                    && hireDay.equals(other.hireDay);
        }
        @Override
        public String toString(){
            return name+" "+salary+"$ "+hireDay;
        }
        public void setName(String s){name = s;}
        public String getName(){return name;}
        public void setSalary(double s){salary = s;}
        public double getSalary(){return salary;}
    }
    protected static class Product implements Serializable{
        private String name;
        private double price;
        private int number;
        //String description;
        public Product (String n,double p,int nm){
            name = n;
            price = p;
            number = nm;
        }
        public void setName(String n){name = n;}
        public void setPrice(double p){price = p;}
        public void setNumber(int n){number = n;}
        public String getName(){return name;}
        public double getPrice(){return price;}
        public int getNumber(){return number;}
        @Override
        public boolean equals(Object o){
            if(this==o)return true;
            if(o==null)return false;
            if(getClass()!=o.getClass())return false;
            Product other=(Product)o;
            return name.equals(other.getName())
                    && price==other.price;
        }
        @Override
        public String toString(){
            return name+" "+price+"$ "+number+"counts";
        }
    }
    protected static class Sale implements Serializable{
        public Employee employee;
        Product product;
        int number;
        Sale(Employee e,Product p,int n){employee=e;product=p;number = n;}
        @Override
        public String toString(){
            return employee.getName()+" "+product.getName()+" "+number;
        }
    }


}

